public class BinaryTreeLeafs {

	static class Node {
		int val;
		Node left, right;
	}

	static class NodeDesc {

		int total, leafs;
	}

	private static NodeDesc getTreeDetails(Node node) {

		NodeDesc desc = new NodeDesc();
		desc.total = 1;
		if (isLeaf(node)) {
			desc.leafs = 1;
		} else {
			NodeDesc leftDesc = new NodeDesc();
			NodeDesc rightDesc = new NodeDesc();
			if (node.left != null) {
				leftDesc = getTreeDetails(node.left);
			}
			if (node.right != null) {
				rightDesc = getTreeDetails(node.right);
			}
			desc.total += leftDesc.total + rightDesc.total;
			desc.leafs += leftDesc.leafs + rightDesc.leafs;

		}

		return desc;
	}

	private static boolean isLeaf(Node node) {

		return node.left == null && node.right == null;
	}

	// Count leaves/total nodes in binary tree
	public static void main(String[] args) {

		Node root = new Node();

		Node n1 = new Node();
		Node n2 = new Node();
		Node n3 = new Node();
		Node n4 = new Node();
		Node n5 = new Node();
		Node n6 = new Node();

		Node n7 = new Node();
		Node n8 = new Node();
		Node n9 = new Node();
		Node n10 = new Node();
		Node n11 = new Node();
		Node n12 = new Node();

		root.left = n1;
		root.right = n7;
		n1.left = n3;
		n1.right = n2; // leaf
		n3.left = n4;
		n3.right = n5; // leaf
		n4.left = null;
		n5.right = n6;// leaf

		n7.right = null;
		n7.left = n8;
		n8.left = n9;
		n8.right = n10;
		n9.left = null;
		n9.right = n11; // leaf
		n10.right = n12;// leaf

		NodeDesc desc = getTreeDetails(root);
		System.out.println(desc.total + " " + desc.leafs);

	}
}
